package faf.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.view.RedirectView;

import faf.business.SheetManager;
import faf.business.SurveyManager;
import faf.business.UserManager;
import faf.entities.Account;
import faf.entities.Sheet;




public class ListSheetController implements Controller {
	UserManager userManager;
	SheetManager sheetManager;
	SurveyManager surveyManager;

	public void setUserManager(UserManager userManager) {
		this.userManager = userManager;
	}

	public void setSheetManager(SheetManager sheetManager) {
		this.sheetManager = sheetManager;
	}

	public void setSurveyManager(SurveyManager surveyManager) {
		this.surveyManager = surveyManager;
	}
	
	@Override
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
	
		Account account = (Account) request.getSession().getAttribute("user");
		if (account == null)
			return new ModelAndView(new RedirectView("login.htm?nexturl=mysheets.htm"));

		List<Sheet> sheets = sheetManager.list(account);
		
		return new ModelAndView("mysheets").addObject("sheets", sheets);
	}

}
